<?php
namespace Admin\Models\ask;

use Admin\Models\BaseModel;

class XhaskSurveyinfo extends BaseModel
{

    /**
     *
     * @var integer
     */
    public $iASIId;

    /**
     *
     * @var integer
     */
    public $iASId;

    /**
     *
     * @var string
     */
    public $iUserId;

    /**
     *
     * @var integer
     */
    public $iStartTime;

    /**
     *
     * @var integer
     */
    public $iEndTime;

    /**
     *
     * @var integer
     */
    public $iTimeCost;

    /**
     *
     * @var string
     */
    public $sUserIP;

    /**
     *
     * @var string
     */
    public $sUserOS;

    /**
     *
     * @var string
     */
    public $sUserBrowser;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {

    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHAsk_SurveyInfo';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhaskSurveyinfo[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhaskSurveyinfo
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * @param $surveyId
     * @param $userId
     * @return XhaskSurveyinfo
     * 根据问卷ID和用户ID获取数据
     * add by ck 20160803
     */
    public static function getRecord($surveyId, $userId)
    {
        $obj = self::findFirst(array(
            'conditions'    => 'iASId = :iASId: AND iUserId = :iUserId:',
            'bind'          => array(
                'iASId'         => $surveyId,
                'iUserId'       => $userId
            )
        ));
        if($obj) return $obj;
        $obj = new self();
        $obj->iASId = $surveyId;
        $obj->iUserId = $userId;
        return $obj;
    }

}
